package org.eclipse.moquette.spi.impl.events;

import org.eclipse.moquette.proto.messages.AbstractMessage;

import java.nio.ByteBuffer;

/**
 * Created by alex on 15-6-1.
 */
public class PublishEvent extends MessagingEvent {

    String m_topic;
    AbstractMessage.QOSType m_qos;
    //publish的数据
    ByteBuffer m_message;
    boolean m_retain; //保留
    String m_clientID;
    //可选属性, 当qos1 和 qos2 的时候需要messageID
    int m_msgID;

    public PublishEvent(String topic, AbstractMessage.QOSType qos, ByteBuffer message, boolean retain, String clientID, Integer msgID) {
        this.m_topic = topic;
        this.m_qos = qos;
        this.m_message = message;
        this.m_retain = retain;
        this.m_clientID = clientID;

        if (qos != AbstractMessage.QOSType.MOST_ONE) {
            this.m_msgID = msgID;
        }
    }
    public String getTopic() {
        return m_topic;
    }

    public AbstractMessage.QOSType getQos() {
        return m_qos;
    }

    public ByteBuffer getMessage() {
        return m_message;
    }

    public boolean isRetain() {
        return m_retain;
    }

    public String getClientID() {
        return m_clientID;
    }

    public int getMessageID() {
        return m_msgID;
    }

    @Override
    public String toString() {
        return "PublishEvent{" +
                "m_msgID=" + m_msgID +
                ", m_clientID='" + m_clientID + '\'' +
                ", m_retain=" + m_retain +
                ", m_qos=" + m_qos +
                ", m_topic='" + m_topic + '\'' +
                '}';
    }
}
